<template>
  <div>
    <van-icon color="#777" name="star-o" @click="collectBtn"  v-if="!articleInfo.is_collected"/>
    <van-icon color="orange" name="star" @click="collectBtn" v-else/>
  </div>
</template>
           
<script>
import {getCollected_api,delCollected_api} from "@/api/search/index"
export default {
  props: ["articleInfo"],
  data() {
    return {};
  },
  methods:{
   async collectBtn() {
       try{
         if(this.articleInfo.is_collected) {
            const {data:res}=await delCollected_api(this.articleInfo.art_id)
            console.log('取消收藏');
         }else {
           const {data:res}=await getCollected_api(this.articleInfo.art_id)
            console.log(res,'收藏成功');
         }
         
       }catch(error) {
           /* if(error.response.status==401){
            return this.$toast('请先登录。。。')
           } */
           return this.$toast('操作失败')
       }
      //  this.articleInfo.is_collected=!this.articleInfo.is_collected
      this.$emit('coll',!this.articleInfo.is_collected)
    }
  }
};
</script>
<style scoped lang="less">
.van-icon-star {
  font-size: 40px;
}
.van-icon {
  font-size: 40px;
}
</style>